var layer;
var element;
var form;
var laydate;
var table;
var upload;
layui.use(['element','layer','laydate','form','table'], function(){
    layer = layui.layer;
    element = layui.element;
    form = layui.form;
    laydate = layui.laydate;
    table = layui.table;
    upload = layui.upload;
    //日期时间范围
    laydate.render({
        elem: '#registerTime'
        ,type: 'datetime'
        ,trigger: 'click' //时间时间为点击事件
        ,range: true
    });
    load();
    selAuditList();


    //但是，如果你的HTML是动态生成的，自动渲染就会失效
    //因此你需要在相应的地方，执行下述方法来进行渲染
    form.render();
})


/**
 *  按钮  点击事件 刷新页面  返回  检索
 * */
function load() {
    //搜索按钮
    $("#indexBtn").bind('click', function () {
        //用户昵称
        var nickname = $("input[name=nickname]").val();
        //课程名称
        var courseName = $("input[name=courseName]").val();
        //订单来源
        var orderSource = $("select[name=orderSource]").val();
        selAuditList(nickname, courseName, orderSource);
    })
}

//刷新页面按钮
$("#refreshs").bind('click', function () {
    location.reload();
})
//重置按钮
$("#resetBtn").bind('click', function () {
    selAuditList();
})

//高级检索
function retrieve(){
    var nicknames=$('input[name=nicknames]').val();
    var orderNo=$('input[name=orderNos]').val();
    var orderSource=$('input[name=orderSources]').val();
    var courseName=$('input[name=courseNames]').val();

    $.post("/SyOperationController/selCourseOrderListData",
        {"orderSource":orderSource,"orderStatus":2,"nickname":nicknames,"orderNo":orderNo,"courseName":courseName},
        function (res) {
            userTab(res.data);
        }
    );
}
//高级检索弹出层
var search=function(){
    layer.open({
        type:2,  //弹出层类型
        title:"高级检索",
        area:['580px','410px'], //弹出层大小
        shade:0.4, //设置遮罩透明度
        offset:'auto', //设置遮罩位置
        content:'CourseUnpaid_search.html', //弹出层内容页面
        success: function (data) {}
    })
    window.layer_1=layer;
}

//查询
function selAuditList(nickname,courseName,orderSource){
    $.post("/SyOperationController/selCourseOrderListData", {"nickname":nickname,"orderStatus":2,"courseName":courseName,"orderSource":orderSource}, function (res) {
        userTab(res.data);
    });
}
//layui-table
function userTab(item){
    table.render({
        elem:"#userListTab",//容器
        title:"课程订单列表",
        data:item,
        toolbar:"#toolbar_id",
        page:true,
        cols:cols
    });
}
//layui-table格式
var cols=[[//定义列
    {type:'checkbox',align:'center',width:40},//复选框靠左
    {title:'序号',align:'center',width:60,templet:function(data){
            return data.LAY_INDEX;
        }},
    {field:"order_no",title:"订单编号",align:'center',width:195},
    {field:"nickname",title:"用户昵称",align:'center',},
    {field:"course_name",title:"课程名称",align:'center',},
    //{field:"phone",title:"用户手机",align:'center',width:120},
    {field:"order_source",title:"订单来源",align:'center',templet:function(data){
            if(data.order_source==2){//2为小程序
                return "小程序";
            }else if(data.order_source==3){//3为app
                return "app"
            }else{
                return "其他"
            }
        }},
    {field:"order_status",title:"订单状态",align:'center',templet:function(data){
            if(data.order_status==2){//待付款
                return "待付款"
            }else if(data.order_status==3){//已付款
                return "已付款"
            }else if(data.order_status==10){//取消交易
                return "取消支付"
            }else{//其他
                return "其他"
            }
        }},
    //{field:"course_intro",title:"课程描述",align:'center',width:120},
    {field:"order_payment_channel",title:"支付渠道",align:'center',templet:function(data){
            if(data.order_payment_channel==2){//2微信支付
                return "微信支付"
            }else if(data.order_payment_channel==3){//3余额支付
                return "余额支付"
            }else if(data.order_payment_channel==4){//4银行卡支付
                return "未支付"
            }else if(data.order_payment_channel==5){//5支付宝支付
                return "支付宝支付"
            }
        }},{field:"true_name",title:"主讲教师",align:'center',width:120},
    {field:"",title:"操作",align:'center',width:100,templet:function(data){
            return "<a style='color:#009688;cursor:pointer;' onclick='selAuditUser(\""+data.order_id+"\")'>查看</a>";
        }}
]];

//查看课程订单详情
var selAuditUser=function(orderId){
    localStorage.setItem("orderId",orderId); //订单ID
    window.location.href='CourseOrderList_layer_sel.html';
}



